package net.tycmc.bulb.function.filter;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

public class MyRequest extends javax.servlet.http.HttpServletRequestWrapper{
	
	public MyRequest(HttpServletRequest request) {
		super(request);
	}

	public String toUTF8(String traned){
        String result=null;
        byte temp[];
        try {
            temp=traned.getBytes("ISO-8859-1");
            result=new String(temp,"UTF-8");
        } catch (UnsupportedEncodingException ex) {
            System.out.println(ex.toString());
        }
        return result;
    }
	
	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		if(null != value && !value.trim().equals("")){
			value = toUTF8(value);
		}
		return value;
	}
	
	@Override
	public String[] getParameterValues(String name) {
		String[] values = super.getParameterValues(name);
		for (int i = 0; i < values.length; i++) {
			values[i] = toUTF8(values[i]);
		}
		return values;
	}

	@Override
	public String getQueryString() {
		String value = super.getQueryString();
		if(null != value && !value.trim().equals("")){
			value = toUTF8(value);
		}
		return value;
	}
}
